package com.train.${module}.mapper;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.train.common.model.page.PageSorted;
import com.train.common.resp.PageResp;
import com.train.${module}.resp.${Domain}PageResp;
import com.train.${module}.dto.${Domain}PageDTO;
import com.train.${module}.po.${Domain}PO;
import com.train.mybatis.base.MyBaseMapper;

import java.util.List;

/**
 * @author ${author}
 * @description 针对表【${domain}(${tableNameCn})】的数据库操作Mapper
 * @createDate ${date}
 * @Entity generator.domain.${Domain}
 */
public interface ${Domain}Mapper extends MyBaseMapper<${Domain}PO> {

    default PageResp<${Domain}PageResp> pageList(${Domain}PageDTO ${domain}PageDTO) {
        PageResp<${Domain}PO> ${domain}POPageResp = this.selectPage(
                ${domain}PageDTO,
                new LambdaQueryWrapper<>(), new PageSorted(${Domain}PO::getUpdateTime), new PageSorted(${Domain}PO::getCreateTime));
        List<${Domain}PageResp> ${domain}PageRespList = BeanUtil.copyToList(${domain}POPageResp.getData(), ${Domain}PageResp.class);
        return new PageResp<>(${domain}POPageResp.getTotal(), ${domain}PageRespList);
    }

    default boolean existsId(Long id) {
        LambdaQueryWrapper<${Domain}PO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(${Domain}PO::getId, id);
        return this.exists(queryWrapper);
    }
}